/*
 * @Descripttion: 
 * @version: 
 * @Author: 川杨
 * @Date: 2022-02-23 15:56:22
 * @LastEditors: 川杨
 * @LastEditTime: 2022-03-02 10:18:57
 */
import './index.scss'
import BizUserCard from './index.vue'

import Vue from 'vue';
import i18n from '@src/locales';
import { destroyComponent } from '@src/util/dom';
import fastCall from '@src/component/util/fastCall.ts';

function getReferenceEl(ref){
  if(ref instanceof HTMLElement) return ref;
  return (typeof ref == 'string' && ref.length > 0) ? document.querySelector(ref) : null;
}

const BizUserCardComp = Vue.extend(BizUserCard);

function initUserCard(options){
  let refEl = getReferenceEl(options.reference);
  if(null == refEl) return console.error(`[${BizUserCard.name}]: need a reference element.`);
  if(!document.body.contains(refEl)) return console.error(`[${BizUserCard.name}]: reference element must be in document`);
  let instance = new BizUserCardComp({
    i18n,
  })
  instance.$mount(refEl);
  return instance
}


const component = {
  install(Vue){
    Vue.component(BizUserCard.name, BizUserCard);
    // 注册快速调用方法
    fastCall(Vue, 'biz', { initUserCard })
  },
  namespace: 'biz',
  props: { initUserCard }
}
export default component;